<link rel="stylesheet" href="/upload/kindeditor/themes/default/default.css" />
	<link rel="stylesheet" href="/upload/kindeditor/plugins/code/prettify.css" />
	<script charset="utf-8" src="/upload/kindeditor/kindeditor.js"></script>
	<script charset="utf-8" src="/upload/kindeditor/lang/zh_CN.js"></script>
	<script charset="utf-8" src="/upload/kindeditor/plugins/code/prettify.js"></script>
        <script type="text/javascript" src="<?php echo $this->module->assetsUrl; ?>/datepicker/WdatePicker.js" /></script>

        <script charset="utf-8" src="<?php echo $this->module->assetsUrl; ?>/js/jquery.Jcrop.js"></script>
        <link rel="stylesheet" href="<?php echo $this->module->assetsUrl; ?>/css/jquery.Jcrop.css" />



<script >
            
            KindEditor.ready(function(K) {
            editor = K.create('#FamousEnterprises_content', {
             allowPreviewEmoticons: false,
            allowImageUpload: true,
            allowFileManager: true,    
            resizeType : 1,
            items : [
           'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage', 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak', 'anchor', 'link', 'unlink', '|', 'about']
            });

            });
     </script>
  
<script >

var url_host = "http://<?php echo Yii::app()->params['HTTP_HOST']; ?>";

function uploadImag(Nid,thumb){
             
             KindEditor.ready(function(K) {
        var editor = K.editor({
            allowPreviewEmoticons: false,
            allowImageUpload: true,
            allowFileManager: false,
            urlType: 'domain'
           // uploadJson : '/uploadImg'
             
        });

            editor.loadPlugin('image', function() {
                editor.plugin.imageDialog({
                    fileUrl: K('#'+Nid).val(),
                    clickFn: function(url, title) {
                        // var file_url_img = "http://m.kxiche.com";
                        //var file_url_img = "http://localhost:8087";
                       // if (url.indexOf("http") > -1) {
                            K('#'+Nid).val(url_host + url);
                            K('#'+thumb).attr('src', url_host + url);
                            K('#jiancai_a_url').attr('src', url_host + url);
                            K('#input_img_url_url').val(url_host + url);
                            K('#'+Nid).attr('type', 'text');                       
                            K('#img_type').val(thumb);
                            
                            
                             if(!K('#btn_cut').text){
                                    K('#'+thumb).after('<button  id="btn_cut" type="button" data-toggle="modal" data-target="#myModal_crop_url" >裁剪</button>');
                             }
                            
                            
                            editor.hideDialog();
                            
                            jiancai_url(thumb);//jcrop初始化
                    }
                });
            });
      });
            
  }
 

</script>



 

<style type="text/css">
 
    .labelForRadio{
       
display:inline-block;
width:auto;float:none;
      }
    
</style>


    
    <div class="control-group">             
        <div class="alert alert-info">
            <?php echo Yii::app()->user->getFlash('addform'); ?>   
        </div>
     </div>
    
    
    <div class="row-fluid">

        <div class="portlet box green">
           <div class="portlet-title line">
                   <div class="caption"><i class="icon-comments"></i>名人名企添加</div>
                   <div class="tools">
                        <a href="javascript:;" class="collapse"></a>
                       
		   </div>
           </div>

           <div class="portlet-body">
                      <?php
                        $form = $this->beginWidget(
                                      'CActiveForm', array(
                                  'id' => 'fc-form',
                                // 'enableAjaxValidation'=>true,   
                                 'enableClientValidation'=>true,
                                  'clientOptions' => array(
                                      'validateOnSubmit' => true,
                                  ),
                                  'htmlOptions' => array('enctype' => 'multipart/form-data', 'class' => 'form-horizontal'),
                                      // 'action'=>array('/admin'),
                              ));
                      ?>	
                                   <?php if(!$AlumniID): ?>
                                        <div class="control-group">
                                            <label class="control-label">急急急</label>
                                            <div class="controls">
                                                  <?php echo  CHtml::dropDownList('FamousEnterprises[alumni_id]','',CHtml::listData(Alumni::model()->findAllByAttributes(array('parent_id'=>$AlumniID)),'id', 'name'));?>
                                            </div>
                                        </div>
                                      

                                    <div class="control-group">
                                        <label class="control-label">是否热点</label>
                                        <div class="controls">
                                            <?php
                                            echo $form->radioButtonList($Fc, 'is_hot', array(1 => '是', 2 => '否'), array(
                                                'separator' => '&nbsp&nbsp&nbsp&nbsp&nbsp',
                                                'labelOptions' => array('class' => 'labelForRadio'),
                                                'style' => 'margin-left:0',
                                            ));
                                            ?>
                                        </div>
                                    </div>

                                       <div class="control-group">
                                           <label class="control-label">标题</label>
                                           <div class="controls">
                                               <?php echo $form->textField($Fc,'title',array('class'=>'m-wrap large','placeholder'=>"标题"))?>
                                               <?php echo $form->error($Fc, 'title', array('class' => 'label label-danger')); ?>
                                           </div>
                                       </div>


                                       <div class="control-group">
                                           <label class="control-label">新闻背景图片</label>
                                           <div class="controls">
                                                   <div class="fileupload fileupload-new" data-provides="fileupload">
                                                       <img id="file_upload_ws" src="<?php echo $Fc->banner_url;?>" width="150" height="85" />
                                                       <input type="hidden" name='FamousEnterprises[banner_url]' value="<?php echo $Fc->banner_url;?>" id="FamousEnterprises_banner_url">
                                                       <input type="button"  id="FamousEnterprises-btn-upload" onclick="uploadImag('FamousEnterprises_banner_url','file_upload_ws')"   value='点击上传' />
                                                       <span> 请上传尺寸为750*445的图!</span>
                                                   </div> 
                                           </div>
                                       </div>


                                       <div class="control-group">
                                           <label class="control-label">内容</label>
                                           <div class="controls">
                                             <?php echo $form->textArea($Fc,'content',array('class'=>'m-wrap','style'=>'width:800px; height:400px;'))?>
                                           </div>
                                       </div>



                                       <div class="form-actions ">
                                           <button type="submit"   class="btn blue"><i class="icon-ok"></i>确定</button>
                                           <button type="button" class="btn">重填</button>
                                       </div>
                                   <?php $this->endWidget(); ?>

           </div>
       </div>

    </div>



<div class="modal fade in" id="myModal_crop_url" tabindex="-1" style="width:auto; margin: -10px 0 0 -350px; max-width:1200px;display:none;" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
              <div class="modal-dialog">
                <div class="modal-content">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">图片剪裁</h4>
                  </div>
                    <div class="modal-body" style="max-height:400px; ">
                       <div class="row-fluid">
                           <div class="span6">
                                <div id="jiancai_a_url_remove">
                                    <img  id="jiancai_a_url" >
                                </div>
                            </div>
                                <input type="hidden" id="x_url" name="x_url" />
                                <input type="hidden" id="y_url" name="y_url" />
                                <input type="hidden" id="w_url" name="w_url" />
                                <input type="hidden" id="h_url" name="h_url" />
                                <input type="hidden" id="input_img_id_url" value="<?php echo $Fc->id;?>" name="input_img_id_url" />
                                <input type="hidden" id="input_img_url_url" name="input_img_url_url" />
                                <input type="hidden" id="img_type" name="img_type" />

                               
                      </div>
                        
                    </div>
                    <div class="modal-footer">
                      <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                      <button type="button" class="btn btn-primary" onclick="img_sub_url()">保存</button>
                    </div>
                </div>
              </div>
            </div>






<script type="text/javascript">


 //裁剪为完成
   //店铺图片上传
    function img_sub_url()
    {
        var x = $('#x_url').val();
        var y = $('#y_url').val();
        var w = $('#w_url').val();
        var h = $('#h_url').val();
        var input_img_url = $('#input_img_url_url').val();
        var input_img_id  = $('#input_img_id_url').val();
        var img_type = $('#img_type').val();
        //var hidden_update_info_url_img = $('#hidden_update_info_url_img_jian').val();
        if(x=='')
        {
            alert('请选择剪裁的区域');
            return false;
        }else
        {
            $.post(
                    '/xyhadm/new/uploads',
                    {
                      'x':x,
                      'y':y,
                      'w':w,
                      'h':h,
                      'input_img_url':input_img_url,
                      'input_img_id':input_img_id,
                      'img_type':img_type
                      //'hidden_update_info_url_img':hidden_update_info_url_img
                    },
                    function(data){
                        
                        if(data){
                            alert('保存成功');
                            $('#myModal_crop_url').modal('hide');
                            
                            $('#'+img_type).removeAttr('src');
                            
                            $('#'+img_type).attr('src',data);
                           // $('#activity_img_cj').attr('style','display:bolck');
                             //parent.location.reload();
                        }
                        else if(data==3)
                        {
                            alert('系统繁忙请稍候在试');
                             $('#myModal_crop_url').modal('hide');
                        }
                                   
                    }
                    );
        }        
    }


    


  //剪切图浏览未完成
    function showPreview(coords) {
        var rx = 150 / coords.w;
        var ry = 150 / coords.h;

        $('#preview').css({
            width: Math.round(rx * 500) + 'px',
            height: Math.round(ry * 370) + 'px',
            marginLeft: '-' + Math.round(rx * coords.x) + 'px',
            marginTop: '-' + Math.round(ry * coords.y) + 'px'
        });
        $('#x').val(coords.x);
        $('#y').val(coords.y);
        $('#w').val(coords.w);
        $('#h').val(coords.h);
    };


   function updateCoords_url(c)
  {
    $('#x_url').val(c.x);
    $('#y_url').val(c.y);
    $('#w_url').val(c.w);
    $('#h_url').val(c.h);
  }

    function WdatePickerSet(val) {
        WdatePicker({dateFmt: 'yyyy-MM-dd HH:mm:ss', minDate: val});
    }
    
 
 function jiancai_url(thumb)
    {
         $('.jcrop-holder').remove(); 
        jcrop_api = $.Jcrop("#jiancai_a_url");
        jcrop_api.destroy();
        
       
            
            if(thumb == 'file_upload_ws'){
                $('#jiancai_a_url').Jcrop({
                    aspectRatio: 750/445,
                    onChange: updateCoords_url,
                  }); 
            }
           
    
    $('#myModal_crop_url').modal('show');
  }
    

</script>

